package com.server.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.server.utility.JsonUtility;
import com.server.utility.RequestUtility;

/**
 * 接口提供方控制层
 */
@Controller
public class ServerController {
	/**
	 * get请求 
	 * @param phoneNumber
	 * @return
	 */
	@RequestMapping(value="/getUserInfo.do",method=RequestMethod.GET)
	@ResponseBody
	public String getUserInfo(@RequestParam String phoneNumber,HttpServletRequest request) {
		Map<String, String> result = new HashMap<String,String>();
		result.put("name", "绝密");
		result.put("userAgent", request.getHeader("userAgent"));
		return JsonUtility.entityToStr(result);
	}
	
	/**
	 * post请求
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/addUserInfo.do",method=RequestMethod.POST)
	@ResponseBody
	public String getUserInfo(HttpServletRequest request) {
		Map<String, String> result = new HashMap<String,String>();
		result.put("requestJson", RequestUtility.readStreamParameter(request));
		result.put("userAgent", request.getHeader("userAgent"));
		return JsonUtility.entityToStr(result);
	}
}
